package com.contactmgr.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
	public static String getFormattedDate(String date) {
		//
		SimpleDateFormat fromUser = new SimpleDateFormat("yyyMMdd");
		SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
		String reformattedStr = "";
		try {
			reformattedStr = myFormat.format(fromUser.parse(date));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return reformattedStr;
	}
	public static String getFormattedDateOfEpoch(String epoch){
		long l = new Long(epoch);
		Date date = new Date(l);
		SimpleDateFormat fromUser = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
		SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd - hh:mm a");
		String reformattedStr = "";
		try {
			reformattedStr = myFormat.format(fromUser.parse(date.toString()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return reformattedStr;
	}
	public static String getFormattedTIme(String time) {
		SimpleDateFormat fromUser2 = new SimpleDateFormat("HHmmss");
		SimpleDateFormat myFormat2 = new SimpleDateFormat("hh:mm a");
		String reformattedStr = "";
		try {
			reformattedStr = myFormat2.format(fromUser2.parse(time));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return reformattedStr;
	}

	public static String getFormattedDuration(int s) {
		return String.format("%d:%02d:%02d", s/3600, (s%3600)/60, (s%60));
	}
}
